package cn.xspace.module.other.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import cn.xspace.module.other.R;
import cn.xspace.module.other.activity.QuestionModuleDetailAct;

/**
 * chong.han 创建于 2017/4/10 0010.
 */
public class SearchAdapter extends BaseAdapter implements View.OnClickListener {
    private Context mContext;

    public SearchAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return 20;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.search_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.search_item_tv.setOnClickListener(this);
        return convertView;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.search_item_tv) {
            String title = ((TextView) v).getText().toString().toString();
            Intent intent = new Intent(mContext, QuestionModuleDetailAct.class);
            intent.putExtra("title", title);
            mContext.startActivity(intent);
        }
    }

    public static class ViewHolder {
        public View rootView;
        public TextView search_item_tv;
        public ImageView search_item_iv;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.search_item_tv = (TextView) rootView.findViewById(R.id.search_item_tv);
            this.search_item_iv = (ImageView) rootView.findViewById(R.id.search_item_iv);
        }

    }
}
